package top.ldkxingzhe.ldksettings.actions

import android.content.Context
import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo
import android.content.pm.PackageParser
import java.io.File

/**
 * Created by liangdengke on 2018/10/19.
 */
class PMHelper(private val context: Context) {
    private val TAG = "ldk.PMHelper"
    private val pm = context.packageManager


    fun printReceiver(info: ActivityInfo){

    }

    fun installedNonSystemApps(): List<ApplicationInfo>{
        return pm.getInstalledApplications(0).filter {
            it.flags and ApplicationInfo.FLAG_SYSTEM == 0
        }
    }

    private fun parsePackage(apkFile: File): PackageParser.Package{
        val packageParser = PackageParser()
        return packageParser.parsePackage(apkFile, 0, true)
    }

    fun parsePackage(applicationInfo: ApplicationInfo): PackageParser.Package{
        return parsePackage(File(applicationInfo.sourceDir))
    }
}